home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9188 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.os.msdos.programmer,comp.lang.c
  4. Subject: Re: What does this do?
  5. Date: 8 Mar 1996 09:34:14 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4hpr2mINN609@keats.ugrad.cs.ubc.ca>
  8. References: <4hg4hv$iqb@hubcap.clemson.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4hg4hv$iqb@hubcap.clemson.edu>,
  12. Chuck Kirschman <ckirsch@eng.clemson.edu> wrote:
  13.  >I'm working in *somebody else's code*, which I'm sure everyone pretty
  14.  >much dreads.  I've run across a construct which I don't understand the
  15.  >purpose of:
  16.  >
  17.  >void foo(int bar, float *baz)
  18.  >{
  19.  >  int x,y;
  20.  >  
  21.  >  (void) x;
  22.  >  (void) y;
  23.  >  
  24.  >  [rest of function]
  25.  >}
  26.  >
  27.  >The compiler (Watcom 10.5) doesn't like it, but lets it pass.  What exactly
  28.  is this doing?  And, more importantly, what is the author trying to acheive?
  29.  
  30. Those lines do nothing. You may safely remove them.
  31.  
  32.  
  33. The only reason for doing something like that would be something like the
  34. following scenario:
  35.  
  36. Suppose expression E refers to a volatile lvalue which represents a hardware
  37. register. When this register is accessed via a read operation, it causes the
  38. device to do something. The value that is read is not interesting at all.
  39.  
  40. In that case, you could use (void) E to cause the read, and discard the value.
  41. If E is a volatile lvalue (such as the name of a variable object declared
  42. volatile), the expression will not be optimized away.
  43.  
  44. In the above example, x and y are simple auto variables that are not volatile,
  45. and certainly don't refer to hardware registers.
  46. -- 
  47.  
  48.